//
//  BabyNameView.m
//  BabyHelper
//
//  Created by  thomas on 11-2-18.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "BabyNameView.h"


@implementation BabyNameView
@synthesize textField;


- (void)viewDidLoad {
	self.title				   = NSLocalizedString(@"Name", @"");
	self.textField.placeholder = NSLocalizedString(@"Please input name...", @"");
    [super viewDidLoad];
	
	UIBarButtonItem *saveItem = [[UIBarButtonItem alloc]
								 initWithTitle:NSLocalizedString(@"Done",@"")
								 style:UIBarButtonItemStyleBordered 
								 target:self
								 action:@selector(toggleSave)		
								 ];
	self.navigationItem.rightBarButtonItem = saveItem;
	[saveItem release];	
	
	//set background image
	self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]];
	self.view.backgroundColor = [UIColor clearColor];
	//set navigation background color
	self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:navBarRed green:navBarGreen blue:navBarBlue alpha:navBarAlpha];
	
}


-(void)viewWillAppear:(BOOL)animated{	
	Dao *dao = [Dao getInstance];
	BabyProfile *babyProfile = [[BabyProfile alloc]init];
	[dao LoadBabyProfile:babyProfile];
	self.textField.text = babyProfile.Name;
	[babyProfile release];
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	self.textField = nil;
}

-(void)toggleSave{
	NSUserDefaults *prefs   = [NSUserDefaults standardUserDefaults];
	[prefs setObject:self.textField.text forKey:@"Name"]; 
	[self.navigationController popViewControllerAnimated:true];		
}

- (void)dealloc {
    [super dealloc];
}
@end
